<template>
	<view class="index">
		<musicHeader title="网易云音乐" :icon="false"></musicHeader>
		<view class="container">
			<scroll-view scroll-y="true">
				<view class="index-search" @tap="handleToSearch">
					<text class="iconfont icon-chazhao"></text>
					<input type="text" placeholder="搜索歌曲" />
				</view>
				<view class="skeleton" v-if="loading">
					<m-for-skeleton
						:avatarSize="200"
						:row="3"
						:title="false"
						:loading="loading"
						isarc="square"
						:titleStyle="{}"
						v-for="(item,key) in 4"
						:key="key">
					</m-for-skeleton>
				</view>
				<view class="index-list" v-else>
					<view class="index-list-item" v-for="(item, index) in topList" :key="index" @tap="handleToList(item.id)">
						<view class="index-list-img">
							<image :src="item.coverImgUrl"></image>
							<text>{{ item.updateFrequency }}</text>
						</view>
						<view class="index-list-text">
							<view v-for="(songs, index) in item.tracks" :key="index">
								{{ index+1 }}.{{ songs.first }}-{{ songs.second }}
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		topList
	} from '../../common/api';
	import musicHeader from '../../components/musicHeader.vue';
	import mForSkeleton from "@/components/m-for-skeleton/m-for-skeleton";
	
	export default {
		data() {
			return {
				topList: [],
				loading: true
			}
		},
		components: {
			musicHeader,
			mForSkeleton
		},
		// 页面加载后触发部分
		onLoad() {
			topList().then((res) => {
				// console.log(res);
				if (res.length) {
					setTimeout(() => {
						this.topList = res
						this.loading = false
					}, 2000)
				}
			})
		},
		methods: {
			handleToList(listId) {
				uni.navigateTo({
					url: '/pages/list/list?listId=' + listId
				});
			},
			handleToSearch() {
				uni.navigateTo({
					url: '/pages/search/search'
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '../../static/iconfont/iconfont.css';

	.index {}

	.index-search {
		display: flex;
		align-items: center;
		height: 70rpx;
		margin: 70rpx 30rpx 30rpx 30rpx;
		background: #f7f7f7;
		border-radius: 50rpx;

		text {
			font-size: 26rpx;
			margin-right: 26rpx;
			margin-left: 28rpx;
		}

		input {
			font-size: 28rpx;
			flex: 1;
		}
	}

	.index-list {
		margin: 0 30rpx;

		.index-list-item {
			display: flex;
			margin-bottom: 35rpx;

			.index-list-img {
				width: 212rpx;
				height: 212rpx;
				margin-right: 20rpx;
				border-radius: 15rpx;
				overflow: hidden;
				position: relative;

				image {
					width: 100%;
					height: 100%;
				}

				text {
					position: absolute;
					font-size: 22rpx;
					color: white;
					bottom: 15rpx;
					left: 15rpx;
				}
			}

			.index-list-text {
				flex: 1;
				font-size: 24rpx;
				line-height: 72rpx;
				
				view {
					width: 58vw;
					white-space: nowrap; // 强制不换行
					overflow: hidden; // 超出部分隐藏
					text-overflow: ellipsis; // 文字隐藏部分添加省略号 
				}
			}
		}
	}
</style>